package com.freeter.modules.FriendShipLink.controller;

import java.util.Arrays;

import com.freeter.common.utils.*;
import com.freeter.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.freeter.common.mpextend.parser.ParseWrapper;


import com.freeter.modules.FriendShipLink.entity.FriendshipLinkEntity;
import com.freeter.modules.FriendShipLink.entity.view.FriendshipLinkView;
import com.freeter.modules.FriendShipLink.entity.model.FriendshipLinkModel;

import com.freeter.modules.FriendShipLink.service.FriendshipLinkService;


/**
 * 
 * 后端接口
 * @author xuchen
 * @email 171998110@qq.com
 * @date 2019-09-04 16:11:48
 */
@RestController
@RequestMapping("FriendShipLink/friendshiplink")
@SuppressWarnings({"unchecked","rawtypes"})
public class FriendshipLinkController {
    @Autowired
    private FriendshipLinkService friendshipLinkService;

    /**
     * 列表
     */
    @RequestMapping("/page")
    @RequiresPermissions("FriendShipLink:friendshiplink:list")
    public PageUtils page(JQPageInfo jqPageInfo,FriendshipLinkModel friendshipLink){
        EntityWrapper< FriendshipLinkEntity> ew = ParseWrapper.parseWrapper(friendshipLink);
     	PageInfo pageInfo = new PageInfo(jqPageInfo);
     	PageUtils page = friendshipLinkService.queryPage(pageInfo, ew);
    
        return page;
        
    }

	/**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("FriendShipLink:friendshiplink:list")
    public R list( FriendshipLinkModel friendshipLink){
       	EntityWrapper< FriendshipLinkEntity> ew = ParseWrapper.parseWrapper(friendshipLink);
        return R.ok().put("data",  friendshipLinkService.selectListView(ew));
    }

	 /**
     * 查询
     */
    @RequestMapping("/query")
    @RequiresPermissions("FriendShipLink:friendshiplink:info")
    public R query(FriendshipLinkEntity friendshipLink){
        EntityWrapper< FriendshipLinkEntity> ew = ParseWrapper.parseWrapper(friendshipLink);
		FriendshipLinkView  friendshipLinkView =  friendshipLinkService.selectView(ew);
		return R.ok("查询成功").put("data",  friendshipLinkView);
    }
	
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("FriendShipLink:friendshiplink:info")
    public R info(@PathVariable("id") String id){
        FriendshipLinkEntity friendshipLink = friendshipLinkService.selectById(id);

        return R.ok().put("friendshipLink", friendshipLink);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("FriendShipLink:friendshiplink:save")
    public R save(@RequestBody FriendshipLinkEntity friendshipLink){
        String uuid = UUIDUtils.getUUID();
        friendshipLink.setId(uuid);
        ValidatorUtils.validateEntity(friendshipLink);
        friendshipLinkService.insert(friendshipLink);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("FriendShipLink:friendshiplink:update")
    public R update(@RequestBody FriendshipLinkEntity friendshipLink){
        ValidatorUtils.validateEntity(friendshipLink);
        friendshipLinkService.updateAllColumnById(friendshipLink);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("FriendShipLink:friendshiplink:delete")
    public R delete(@RequestBody String[] ids){
        friendshipLinkService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
